<?php
/**
 * Created by PhpStorm.
 * User: yf
 * Date: 2017/3/15
 * Time: 下午8:22
 */

namespace App\Controller\Api;


use App\Utility\VerifyCode\Verify;
use Core\AbstractInterface\AbstractController;
use Core\Utility\Random;

class Code extends AbstractController
{

    function index()
    {
        // TODO: Implement index() method.
        $this->response()->write("verify");/*  url:domain/api/auth/index.html  domain/api/auth/   */
    }

    public function afterAction()
    {
        // TODO: Implement afterAction() method.
    }

    function onRequest($actionName)
    {
        // TODO: Implement onRequest() method.
    }

    function actionNotFound($actionName = null, $arguments = null)
    {
        // TODO: Implement actionNotFount() method.
    }

    function afterResponse()
    {
        // TODO: Implement afterResponse() method.
    }

    public function code()
    {
        $code = Verify::create(Random::randStr(4));
        //$this->response()->write($code->getImageSting());
        $this->response()->write( $code->getImageMineType() );
        //$this->response()->withHeader("Content-type" , $code->getImageMineType());
        $this->response()->setCookie('code', $code->getCodeStr());
    }

    public function verify()
    {
        $code = Verify::create(Random::randStr(4));
        $this->response()->write($code->getImageSting());
        $this->response()->withHeader("Content-type",$code->getImageMineType());
        $this->response()->setCookie("imageCode",$code->getCodeStr());
    }

    public function test()
    {
        $this->response()->write('ok');
    }
}